package com.iot.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.iot.model.query.DeviceDataStepsQuery;
import com.iot.model.dto.DeviceDataStepsDto;
import com.iot.model.vo.AuthInfoVo;
import com.iot.service.DeviceDataStepsService;
import com.iot.commons.ResponseResult;
import com.iot.utils.ResponseResultUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 
 * @author: dh
 * @date: 2024-04-21 10:52:03
 */
@RestController
@RequestMapping("/deviceDataSteps")
@RequiredArgsConstructor
public class DeviceDataStepsController {

    private final DeviceDataStepsService deviceDataStepsService;

    /**
     * 分页条件搜索实现
     * @param deviceDataSteps
     * @return resultList
     */
    @PostMapping(value = "/getList")
    public ResponseResult getList(@RequestBody DeviceDataStepsQuery deviceDataSteps) {
        return  deviceDataStepsService.getList(deviceDataSteps);
    }

    /**
     * 修改
     * @param deviceDataSteps
     * @return
     */
    @PostMapping(value = "/edit")
    public ResponseResult edit(@RequestBody DeviceDataStepsDto deviceDataSteps) {
        return deviceDataStepsService.edit(deviceDataSteps);
    }

    /**
     * 新增
     * @param deviceDataSteps
     * @return
     */
    @PostMapping(value = "/upload")
    public ResponseResult upload(@RequestBody List<DeviceDataStepsDto> deviceDataSteps) {
        AuthInfoVo authInfoEntity = (AuthInfoVo) StpUtil.getSession().get("loginInfo");
        if (null == authInfoEntity) {
            return ResponseResultUtil.authInfoFailure();
        }
        return deviceDataStepsService.upload(deviceDataSteps,authInfoEntity.getId());
    }

    /**
     * 详情
     * @param deviceDataSteps
     * @return
     */
    @PostMapping(value = "/getById")
    public ResponseResult getById(@RequestBody DeviceDataStepsQuery deviceDataSteps) {
        return deviceDataStepsService.getById(deviceDataSteps);
    }
}
